﻿using FPP.Models;
using NUnit.Framework;

namespace FPP.Tests.Models
{
    public class UserModelTest : BaseTest
    {

        [TestFixture]
        public class AddUser : BaseTest
        {
            [TestFixtureSetUp]
            public void AddUserSetUp()
            {
                _context = new FakeFppEntities();
            }

            [Test]
            public void FirstNameIsRequired()
            {
                var repository = new FppRepository(_context);
                var newUser = new User();
                newUser.Email = "Johnny@example.com";

                var response = repository.AddUser(newUser);

                //Should be false because a first name doesnt exist
                Assert.AreEqual(false, response);

                newUser.FirstName = "Johnny";
                response = repository.AddUser(newUser);

                //Should now be true because a first name now exists
                Assert.AreEqual(true, response);
            }

            [Test]
            public void EmailIsRequired()
            {
                var repository = new FppRepository(_context);
                var newUser = new User();
                newUser.FirstName = "Johnny";

                var response = repository.AddUser(newUser);
                //Should be false because there is no email
                Assert.AreEqual(false, response);

                newUser.Email = "Johnny@example.com";
                response = repository.AddUser(newUser);

                //Should now be true because email exists
                Assert.AreEqual(true, response);
            }

            [Test]
            public void EmailIsInCorrectFormat()
            {
                var repository = new FppRepository(_context);
                var newUser = new User();
                newUser.FirstName = "Johnny";
                newUser.Email = "Johnny";

                var response = repository.AddUser(newUser);
                //Should be false because email is not in the correct format
                Assert.AreEqual(false, response);

                newUser.Email = "Johnny@example.com";
                response = repository.AddUser(newUser);
                //Should now be true because email is in the correct format
                Assert.AreEqual(true, response);

            }
        }

    }
}
